/**
 * 初始化省市县联动控件
 * @author 江雄
 * @param provinceSelId
 * @param citySelId
 * @param districtSelId
 * @param townId,
 * @param currentProvinceId 当前省份值 没有不传
 * @param currentcityId 当前市值 没有传不传
 * @param currentdistrictId 当前区县值没有传不传
 *  @param currentTownId 当前街道乡镇值没有传不传
 * @auto
 */
function initArea(
    provinceSelId,citySelId,districtSelId,townId,

    currentProvinceId,currentcityId,currentdistrictId,currentTownId){
    $('#'+provinceSelId).unbind("change");
    $('#'+citySelId).unbind("change");
    $('#'+districtSelId).unbind("change");
    $('#'+townId).unbind("change");
    removAlleSelect(provinceSelId);
    var provinceDom = document.getElementById(provinceSelId);
    provinceDom.options[provinceDom.length] = new Option("-选择省份-","");
    jQuery.get("/sunday/web/area/getProvince",{},function(province_arr){
        for(var i=0;i<province_arr.length;i++){
            provinceDom.options[provinceDom.length] = new Option(province_arr[i].name,province_arr[i].id);
        }

        var cityDom = document.getElementById(citySelId);
        cityDom.options[cityDom.length] = new Option("-选择市-","");

        var districtDom = document.getElementById(districtSelId);
        districtDom.options[districtDom.length] = new Option("-选择区县-","");

        var townDom = document.getElementById(townId);
        townDom.options[townDom.length] = new Option("-选择街道乡镇-","");





        $("#"+provinceSelId).change(function(){
            removAlleSelect(citySelId);
            cityDom.options[cityDom.length] = new Option("-选择市-","");
            if($(this).val()!=""){
                jQuery.get("/sunday/web/area/getCity",{provinceId:$(this).val()},function(data){
                    for(var i=0;i<data.length;i++){
                        cityDom.options[cityDom.length] = new Option(data[i].name,data[i].id);
                    }
                    removAlleSelect(districtSelId);
                    districtDom.options[districtDom.length] = new Option("-选择县市区-","");


                    removAlleSelect(townId);
                    townDom.options[townDom.length] = new Option("-选择街道乡镇-","");
                });
            }
        });

        $("#"+citySelId).change(function(){
            removAlleSelect(districtSelId);
            if($(this).val()!=""){
                districtDom.options[districtDom.length] = new Option("-选择县市区-","");
                jQuery.get("/sunday/web/area/getDistrict",{cityId:$(this).val()},function(data){
                    for(var i=0;i<data.length;i++){
                        districtDom.options[districtDom.length] = new Option(data[i].name,data[i].id);
                    }
                });
                removAlleSelect(townId);
                townDom.options[townDom.length] = new Option("-选择街道乡镇-","");
            }
        });

        $("#"+districtSelId).change(function(){

            removAlleSelect(townId);
            if($(this).val()!=""){
                townDom.options[townDom.length] = new Option("-选择街道乡镇-","");
                jQuery.get("/sunday/web/area/getTown",{districtId:$(this).val()},function(data){
                    for(var i=0;i<data.length;i++){
                        townDom.options[townDom.length] = new Option(data[i].name,data[i].id);
                    }
                });
            }
        });




        if(typeof currentProvinceId!='undefined'&&currentProvinceId!=null&&currentProvinceId!=""){
            provinceDom.value=currentProvinceId;

            jQuery.get("/sunday/web/area/getCity",{provinceId:currentProvinceId},function(data){
                for(var i=0;i<data.length;i++){
                    cityDom.options[cityDom.length] = new Option(data[i].name,data[i].id);
                }
                if(typeof currentcityId!='undefined'&&currentcityId!=null&&currentcityId!=""){
                    cityDom.value=currentcityId;
                    jQuery.get("/sunday/web/area/getDistrict",{cityId:currentcityId},function(data){
                        for(var i=0;i<data.length;i++){
                            districtDom.options[districtDom.length] = new Option(data[i].name,data[i].id);
                        }
                        if(typeof currentdistrictId!='undefined'&&currentdistrictId!=null&&currentdistrictId!=""){
                            districtDom.value=currentdistrictId;
                        }
                    });
                    if(typeof currentTownId!='undefined'&&currentTownId!=null&&currentTownId!=""){
                        townDom.value=currentTownId;
                        jQuery.get("/sunday/web/area/getTown",{districtId:currentdistrictId},function(data){
                            for(var i=0;i<data.length;i++){
                                townDom.options[townDom.length] = new Option(data[i].name,data[i].id);
                            }
                            if(typeof currentTownId!='undefined'&&currentTownId!=null&&currentTownId!=""){
                                townDom.value=currentTownId;
                            }
                        });

                    }
                }
            });
        }
    });
}


/**
 * 初始化省市县联动控件
 * @author ChenJunhui
 * @param provinceSelId
 * @param citySelId
 * @param districtSelId
 * @param currentProvinceId 当前省份值 没有不传
 * @param currentcityId 当前地区值 没有传不传
 * @param currentdistrictId 当前城市值没有传不传
 * @auto 江雄2015年12月25日自定义。乱改直接往屎里打！！！！！！！！
 */
function intAreaNoTown(
    provinceSelId,citySelId,districtSelId,
    currentProvinceId,currentcityId,currentdistrictId){

    $('#'+provinceSelId).unbind("change");
    $('#'+citySelId).unbind("change");
    $('#'+districtSelId).unbind("change");
    removAlleSelect(provinceSelId);
    var provinceDom = document.getElementById(provinceSelId);
    provinceDom.options[provinceDom.length] = new Option("选择省份","");
    jQuery.get("/sunday/web/area/getProvince",{},function(province_arr){
        for(var i=0;i<province_arr.length;i++){
            provinceDom.options[provinceDom.length] = new Option(province_arr[i].name,province_arr[i].id);
        }

        var cityDom = document.getElementById(citySelId);
        cityDom.options[cityDom.length] = new Option("选择市","");

        var districtDom = document.getElementById(districtSelId);
        districtDom.options[districtDom.length] = new Option("选择区县","");


        $("#"+provinceSelId).change(function(){
            removAlleSelect(citySelId);
            cityDom.options[cityDom.length] = new Option("选择市","");
            if($(this).val()!=""){
                jQuery.get("/sunday/web/area/getCity",{provinceId:$(this).val()},function(data){
                    for(var i=0;i<data.length;i++){
                        cityDom.options[cityDom.length] = new Option(data[i].name,data[i].id);
                    }
                    removAlleSelect(districtSelId);
                    districtDom.options[districtDom.length] = new Option("选择县市区","");
                });
            }
        });

        $("#"+citySelId).change(function(){
            removAlleSelect(districtSelId);
            if($(this).val()!=""){
                districtDom.options[districtDom.length] = new Option("选择县市区","");
                jQuery.get("/sunday/web/area/getDistrict",{cityId:$(this).val()},function(data){
                    for(var i=0;i<data.length;i++){
                        districtDom.options[districtDom.length] = new Option(data[i].name,data[i].id);
                    }
                });

            }
        });

        if(typeof currentProvinceId!='undefined'&&currentProvinceId!=null&&currentProvinceId!=""){
            provinceDom.value=currentProvinceId;

            jQuery.get("/sunday/web/area/getCity",{provinceId:currentProvinceId},function(data){
                for(var i=0;i<data.length;i++){
                    cityDom.options[cityDom.length] = new Option(data[i].name,data[i].id);
                }
                if(typeof currentcityId!='undefined'&&currentcityId!=null&&currentcityId!=""){
                    cityDom.value=currentcityId;
                    jQuery.get("/sunday/web/area/getDistrict",{cityId:currentcityId},function(data){
                        for(var i=0;i<data.length;i++){
                            districtDom.options[districtDom.length] = new Option(data[i].name,data[i].id);
                        }
                        if(typeof currentdistrictId!='undefined'&&currentdistrictId!=null&&currentdistrictId!=""){
                            districtDom.value=currentdistrictId;
                        }
                    });
                }
            });
        }
    });
}
/**
 * 初始化省市县联动控件
 * @author ChenJunhui
 * @param provinceSelId
 * @param citySelId
 * @param districtSelId
 * @param currentProvinceId 当前省份值 没有不传
 * @param currentcityId 当前地区值 没有传不传
 * @param currentdistrictId 当前城市值没有传不传
 * @auto 江雄2015年12月25日自定义。乱改直接往屎里打！！！！！！！！
 */
function doInitCityNoTownSelect(
    provinceSelId,citySelId,districtSelId,
    currentProvinceId,currentcityId,currentdistrictId){

    $('#'+provinceSelId).unbind("change");
    $('#'+citySelId).unbind("change");
    $('#'+districtSelId).unbind("change");
    removAlleSelect(provinceSelId);
    var provinceDom = document.getElementById(provinceSelId);
    provinceDom.options[provinceDom.length] = new Option("-选择省份-","");
    jQuery.get("/sunday/web/area/getProvince",{},function(province_arr){
        for(var i=0;i<province_arr.length;i++){
            provinceDom.options[provinceDom.length] = new Option(province_arr[i].name,province_arr[i].id);
        }

        var cityDom = document.getElementById(citySelId);
        cityDom.options[cityDom.length] = new Option("-选择市-","");

        var districtDom = document.getElementById(districtSelId);
        districtDom.options[districtDom.length] = new Option("-选择区县-","");


        $("#"+provinceSelId).change(function(){
            removAlleSelect(citySelId);
            cityDom.options[cityDom.length] = new Option("-选择市-","");
            if($(this).val()!=""){
                jQuery.get("/sunday/web/area/getCity",{provinceId:$(this).val()},function(data){
                    for(var i=0;i<data.length;i++){
                        cityDom.options[cityDom.length] = new Option(data[i].name,data[i].id);
                    }
                    removAlleSelect(districtSelId);
                    districtDom.options[districtDom.length] = new Option("-选择县市区-","");
                });
            }
        });

        $("#"+citySelId).change(function(){
            removAlleSelect(districtSelId);
            if($(this).val()!=""){
                districtDom.options[districtDom.length] = new Option("-选择县市区-","");
                jQuery.get("/sunday/web/area/getDistrict",{cityId:$(this).val()},function(data){
                    for(var i=0;i<data.length;i++){
                        districtDom.options[districtDom.length] = new Option(data[i].name,data[i].id);
                    }
                });

            }
        });

        if(typeof currentProvinceId!='undefined'&&currentProvinceId!=null&&currentProvinceId!=""){
            provinceDom.value=currentProvinceId;

            jQuery.get("/sunday/web/area/getCity",{provinceId:currentProvinceId},function(data){
                for(var i=0;i<data.length;i++){
                    cityDom.options[cityDom.length] = new Option(data[i].name,data[i].id);
                }
                if(typeof currentcityId!='undefined'&&currentcityId!=null&&currentcityId!=""){
                    cityDom.value=currentcityId;
                    jQuery.get("/sunday/web/area/getDistrict",{cityId:currentcityId},function(data){
                        for(var i=0;i<data.length;i++){
                            districtDom.options[districtDom.length] = new Option(data[i].name,data[i].id);
                        }
                        if(typeof currentdistrictId!='undefined'&&currentdistrictId!=null&&currentdistrictId!=""){
                            districtDom.value=currentdistrictId;
                        }
                    });
                }
            });
        }
    });
}

function removAlleSelect(selId){
    var selDomObj = document.getElementById(selId);
    for(var i=selDomObj.length-1;i>=0;i--){
        selDomObj.remove(i);
    }
}